package swagger

import (
	"net/http"
	"strings"

	"gitee.com/jimoqiongyin/goctl/api/spec"
)

// TODO 我加的函数
func consumesFromTypeOrDefMy(ctx Context, method string, tp spec.Type, properties map[string]string) []string {
	if strings.EqualFold(method, http.MethodGet) {
		return []string{}
	}
	if tp == nil {
		return []string{}
	}
	structType, ok := tp.(spec.DefineStruct)
	if !ok {
		return []string{}
	}
	if typeContainsTag(ctx, structType, tagJson) {
		return []string{applicationJson}
	}
	if value, ok := properties["consumes"]; ok {
		if strings.ToLower(value) == "formdata" {
			return []string{applicationFormData}
		}
		return strings.Split(value, ";")
	}
	return []string{applicationForm}
}

func consumesFromTypeOrDef(ctx Context, method string, tp spec.Type) []string {
	if strings.EqualFold(method, http.MethodGet) {
		return []string{}
	}
	if tp == nil {
		return []string{}
	}
	structType, ok := tp.(spec.DefineStruct)
	if !ok {
		return []string{}
	}
	if typeContainsTag(ctx, structType, tagJson) {
		return []string{applicationJson}
	}
	return []string{applicationForm}
}
